home *** CD-ROM | disk | FTP | other *** search
/ Freelog 115 / FreelogNo115-MaiJuin2013.iso / Internet / AvantBrowser / asetup.exe / _data / webkit / resources.pak / Unnamed File 000103.txt < prev    next >
Text File  |  2013-04-03  |  5KB  |  181 lines

  1. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. (function() {
  6. var dumpToTextButton = $('dump-to-text');
  7. var dataDump = $('data-dump');
  8. dumpToTextButton.addEventListener('click', function(event) {
  9.   // TODO(akalin): Add info like Chrome version, OS, date dumped, etc.
  10.  
  11.   var data = '';
  12.   data += '======\n';
  13.   data += 'Status\n';
  14.   data += '======\n';
  15.   data += JSON.stringify(chrome.sync.aboutInfo, null, 2);
  16.   data += '\n';
  17.   data += '\n';
  18.  
  19.   data += '=============\n';
  20.   data += 'Notifications\n';
  21.   data += '=============\n';
  22.   data += JSON.stringify(chrome.sync.notifications, null, 2);
  23.   data += '\n';
  24.   data += '\n';
  25.  
  26.   data += '===\n';
  27.   data += 'Log\n';
  28.   data += '===\n';
  29.   data += JSON.stringify(chrome.sync.log.entries, null, 2);
  30.   data += '\n';
  31.  
  32.   dataDump.textContent = data;
  33. });
  34.  
  35. // TODO(mmontgomery): add SPECIFICS as an opt-in.
  36. var allFields = [
  37.   'ID',
  38.   'IS_UNSYNCED',
  39.   'IS_UNAPPLIED_UPDATE',
  40.   'BASE_VERSION',
  41.   'BASE_VERSION_TIME',
  42.   'SERVER_VERSION',
  43.   'SERVER_VERSION_TIME',
  44.   'PARENT_ID',
  45.   'SERVER_PARENT_ID',
  46.   'IS_DEL',
  47.   'SERVER_IS_DEL',
  48.   'serverModelType',
  49. ];
  50.  
  51. function versionToDateString(version) {
  52.   // TODO(mmontgomery): ugly? Hacky? Is there a better way?
  53.   var epochLength = Date.now().toString().length;
  54.   var epochTime = parseInt(version.slice(0, epochLength));
  55.   var date = new Date(epochTime);
  56.   return date.toString();
  57. }
  58.  
  59. function getFields(node) {
  60.   return allFields.map(function(field) {
  61.     var fieldVal;
  62.     if (field == 'SERVER_VERSION_TIME') {
  63.       var version = node['SERVER_VERSION'];
  64.       fieldVal = versionToDateString(version);
  65.     } if (field == 'BASE_VERSION_TIME') {
  66.       var version = node['BASE_VERSION'];
  67.       fieldVal = versionToDateString(version);
  68.     } else {
  69.       fieldVal = node[field];
  70.     }
  71.     return fieldVal;
  72.   });
  73. }
  74.  
  75. function isSelectedDatatype(node) {
  76.   var type = node.serverModelType;
  77.   var typeCheckbox = $(type);
  78.   // Some types, such as 'Top level folder', appear in the list of nodes
  79.   // but not in the list of selectable items.
  80.   if (typeCheckbox == null) {
  81.     return false;
  82.   }
  83.   return typeCheckbox.checked;
  84. }
  85.  
  86. function makeBlobUrl(data) {
  87.   var textBlob = new Blob([data], {type: 'octet/stream'});
  88.   var blobUrl = window.webkitURL.createObjectURL(textBlob);
  89.   return blobUrl;
  90. }
  91.  
  92. function makeDownloadName() {
  93.   // Format is sync-data-dump-$epoch-$year-$month-$day-$OS.csv.
  94.   var now = new Date();
  95.   var friendlyDate = [now.getFullYear(),
  96.                       now.getMonth() + 1,
  97.                       now.getDate()].join('-');
  98.   var name = ['sync-data-dump',
  99.               friendlyDate,
  100.               Date.now(),
  101.               navigator.platform].join('-');
  102.   return [name, 'csv'].join('.');
  103. }
  104.  
  105. function makeDateUserAgentHeader() {
  106.   var now = new Date();
  107.   var userAgent = window.navigator.userAgent;
  108.   var dateUaHeader = [now.toISOString(), userAgent].join(',');
  109.   return dateUaHeader;
  110. }
  111.  
  112. function triggerDataDownload(data) {
  113.   // Prepend a header with ISO date and useragent.
  114.   var output = [makeDateUserAgentHeader()];
  115.   output.push('=====');
  116.  
  117.   var aboutInfo = JSON.stringify(chrome.sync.aboutInfo, null, 2);
  118.   output.push(aboutInfo);
  119.  
  120.   if (data != null && data.length > 0) {
  121.     output.push('=====');
  122.     var fieldLabels = allFields.join(',');
  123.     output.push(fieldLabels);
  124.  
  125.     var data = data.filter(isSelectedDatatype);
  126.     data = data.map(getFields);
  127.     var dataAsString = data.join('\n');
  128.     output.push(dataAsString);
  129.   }
  130.   output = output.join('\n');
  131.  
  132.   var anchor = $('dump-to-file-anchor');
  133.   anchor.href = makeBlobUrl(output);
  134.   anchor.download = makeDownloadName();
  135.   anchor.click();
  136. }
  137.  
  138. function createTypesCheckboxes(types) {
  139.   var containerElt = $('node-type-checkboxes');
  140.  
  141.   types.map(function(type) {
  142.     var div = document.createElement('div');
  143.  
  144.     var checkbox = document.createElement('input');
  145.     checkbox.id = type;
  146.     checkbox.type = 'checkbox';
  147.     checkbox.checked = 'yes';
  148.     div.appendChild(checkbox);
  149.  
  150.     var label = document.createElement('label');
  151.     // Assigning to label.for doesn't work.
  152.     label.setAttribute('for', type);
  153.     label.innerText = type;
  154.     div.appendChild(label);
  155.  
  156.     containerElt.appendChild(div);
  157.   });
  158. }
  159.  
  160. function populateDatatypes(childNodeSummaries) {
  161.   var types = childNodeSummaries.map(function(n) {
  162.     return n.type;
  163.   });
  164.   types = types.sort();
  165.   createTypesCheckboxes(types);
  166. }
  167.  
  168. document.addEventListener('DOMContentLoaded', function() {
  169.   chrome.sync.getRootNodeDetails(function(rootNode) {
  170.     chrome.sync.getChildNodeIds(rootNode.id, function(childNodeIds) {
  171.       chrome.sync.getNodeSummariesById(childNodeIds, populateDatatypes);
  172.     });
  173.   });
  174. });
  175.  
  176. var dumpToFileLink = $('dump-to-file');
  177. dumpToFileLink.addEventListener('click', function(event) {
  178.   chrome.sync.getAllNodes(triggerDataDownload);
  179. });
  180. })();
  181.